package com.pubinfo.passbook.common.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.pubinfo.passbook.common.model.http.User.EInvoice;
import com.pubinfo.passbook.common.model.http.User.EInvoiceId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * @TableName t_passbook_persion_info
 */
@TableName(value ="t_passbook_persion_info")
@Data
@NoArgsConstructor
@ApiModel(value = "TPassbookPersionInfo", description = "个人票据信息表")
public class TPassbookPersionInfo implements Serializable {
    /**
     * 
     */
    @TableId
    private String id;
    
    /**
     *
     */
    @ApiModelProperty("是否成功")
    private Integer isSucceed;

    /**
     * 
     */
    private Date createTime;

    /**
     * 
     */
    @ApiModelProperty("票据列表")
    private String eInvoiceList;

    /**
     * 
     */
    @ApiModelProperty("所属公司")
    private String enterId;

    /**
     * 
     */
    @ApiModelProperty("身份证")
    private String usercode;
    
    /**
     *
     */
    @ApiModelProperty("用户名")
    private String username;
    
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    
    public TPassbookPersionInfo(EInvoice eInvoice) {
        this.isSucceed = 0;
        this.enterId = eInvoice.getEnterId();
        this.usercode = eInvoice.getUsercode();
        this.username = eInvoice.getUsername();
        //
        this.eInvoiceList = JSON.toJSONString(eInvoice.getEInvoiceList());
    }
    
    public List<String> toList() {
        //List<EInvoiceId> eInvoiceList = Arrays.asList(this.eInvoiceList);
        List<EInvoiceId> eInvoiceList = JSONObject.parseArray(this.eInvoiceList, EInvoiceId.class);
        List<String> strList = eInvoiceList.stream().map(EInvoiceId::getEInvoiceId).collect(Collectors.toList());
        return strList;
    }
}